package com.example.demo.dao;

import com.example.demo.model.ArticleInfo;
import com.example.demo.model.vo.UserinfoVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description
 * User: 杰
 * Date: 2023 -08 -12
 * Time: 20:35
 */
@Mapper
public interface ArticleMapper {

    @Select("select * from articleinfo where uid=#{uid} order by id desc")
    List<ArticleInfo> getListByUid(@Param("uid")int uid);

    @Delete("delete from articleinfo where id=#{aid} and uid=#{uid}")
    int del(@Param("aid")Integer aid, int uid);

    @Insert("insert into articleinfo(title,content,uid) values(#{title},#{content},#{uid})")
    int add(ArticleInfo articleInfo);

    @Select("select * from articleinfo where id=#{id} and uid = #{uid}")
    ArticleInfo getArticleByUidAndId(@Param("id") Integer aid, int uid);

    @Update("update articleinfo set content=#{content},title=#{title} where uid=#{uid} and id=#{id}")
    int UpdateByUidAndId(ArticleInfo articleInfo);

    @Select("select * from articleinfo where id=#{aid}")
    ArticleInfo getDetailById(@Param("aid") int aid);

    @Select("select count(*) from articleinfo where uid = #{uid}")
    int getArtCountByUid(@Param("uid")int uid);

    @Update("update articleinfo set rcount = rcount+1 where id=#{aid}")
    int incrementRCount(@Param("aid") int aid);

    @Select("select * from articleinfo order by id desc limit #{psize} offset #{offset}")
    public List<ArticleInfo> getListByPage(@Param("psize")int psize, @Param("offset") int offset);

    @Select("select count(*) from articleinfo")
    int getCount();
}


